Skip to content

fix: secret scanning broken in Docker — missing git binary + exit code ambiguity#202

Merged
coopernetes merged 1 commit into
mainfrom
fix/189-gitleaks-rsa-detection
May 4, 2026
Merged

fix: secret scanning broken in Docker — missing git binary + exit code ambiguity#202
coopernetes merged 1 commit into
mainfrom
fix/189-gitleaks-rsa-detection

Conversation

@coopernetes
Copy link
Copy Markdown
Member

@coopernetes coopernetes commented May 4, 2026

Summary

  • Root cause of bug: gitleaks not detecting legit secrets (RSA private key) #189: The Docker runtime image was missing the `git` binary. `gitleaks git` mode shells out to `git` to traverse commit history — without it, gitleaks exits 1 with an empty report. The proxy misread exit 1 as "findings present, read report", got an empty list, and silently passed the push.
  • Secondary fix: Use `--exit-code 2` so gitleaks findings produce exit 2, making runtime errors (exit 1) unambiguous from clean scans (exit 0) and findings (exit 2).
  • Fail-closed: When `secret-scan: enabled: true` and the scanner errors or is unavailable, the push is now blocked with a clear message instead of silently passing.
  • Smoke tests upgraded: Fake truncated PEM keys replaced with real keys from `openssl`/`ssh-keygen` (with fallback detection). Added PKCS#8 (`BEGIN PRIVATE KEY`) alongside PKCS#1 (`BEGIN RSA PRIVATE KEY`).
  • CI: New `docker-smoke-test` job builds the image, seeds Gitea, and runs `push-fail-secrets.sh` + `proxy-fail-secrets.sh` end-to-end against the real Docker distribution.
  • Descriptive error on blocked `/info/refs`: Previously returned a bare 403 with no body.

Test plan

  • CI passes — `docker-smoke-test` job blocks all secret-containing pushes
  • `GitleaksRunnerTest` — 4 tests covering `scanGit` and `scan` modes
  • `SecretScanningFilterTest#scannerUnavailable_failClosed` — scanner error produces FAIL step
  • `UrlRuleFilterTest` — descriptive `sendError` + `recordFetch` on blocked `/info/refs`
  • Local: `source test/gitea/env.sh && bash test/push-fail-secrets.sh && bash test/proxy-fail-secrets.sh`

closes #189
closes #200

@coopernetes coopernetes enabled auto-merge May 4, 2026 04:30
@coopernetes coopernetes disabled auto-merge May 4, 2026 04:32
…e ambiguity

Root cause of #189: The Docker runtime image was missing the `git` binary.
gitleaks git mode shells out to `git` to traverse commit history — without
it, gitleaks exits 1 with an empty report. The proxy misread exit 1 as
"findings present, read report", got an empty list, and silently passed.

Secondary fix: use --exit-code 2 so gitleaks findings produce exit 2, making
runtime errors (exit 1) unambiguous from clean scans (exit 0).

Fail-closed: when secret-scan is enabled and the scanner errors or is
unavailable, the push is now blocked with a clear message instead of silently
passing.

Smoke tests upgraded: fake truncated PEM keys replaced with real keys from
openssl/ssh-keygen (with fallback detection). Added PKCS#8 (BEGIN PRIVATE KEY)
alongside PKCS#1 (BEGIN RSA PRIVATE KEY).

CI: docker-smoke-test job now runs as a matrix across db: [default, postgres,
mongo] with fail-fast: false. Fixed compose.sh to prefer docker over podman
when the docker daemon is confirmed running via `docker info`, avoiding a
failure on GitHub Actions ubuntu-24.04 where the podman binary exists but its
socket is not running.

Descriptive error on blocked /info/refs: previously returned a bare 403.

closes #189
closes #200

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coopernetes coopernetes force-pushed the fix/189-gitleaks-rsa-detection branch from 9fb6ee4 to 67360c4 Compare May 4, 2026 04:43
@coopernetes coopernetes enabled auto-merge May 4, 2026 04:43
@coopernetes coopernetes merged commit 805d585 into main May 4, 2026
16 checks passed
@coopernetes coopernetes deleted the fix/189-gitleaks-rsa-detection branch May 4, 2026 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: blocked info/refs returns bare 403 with no user-facing explanation bug: gitleaks not detecting legit secrets (RSA private key)

1 participant